﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Survey.Entity;
using Survey.DataAccessLayer.Data;

namespace Survey.DataAccessLayer
{
    public class QuestionOptionAccessor : Accessor<QuestionOption>
    {
        public QuestionFeedbackAccessor _feedbackAccessor;
        public QuestionOptionAccessor() : base(new SurveyDbContext())
        {
            _feedbackAccessor = new QuestionFeedbackAccessor();
        }
        public QuestionOption GetQuestionOption(int id)
        {
            var q = Select(questionOption => questionOption.Id == id);
            return q.Single();
        }
        /// <summary>
        /// 获得选项被选择的次数
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int GetSelectionTimes(int id)
        {
            QuestionOption questionOption = Select(qo => qo.Id == id).Single();
            return GetSelectionTimes(questionOption);
        }
        /// <summary>
        /// 获得选项被选择的次数
        /// </summary>
        /// <param name="questionOption"></param>
        /// <returns></returns>
        public int GetSelectionTimes(QuestionOption questionOption)
        {
            return _feedbackAccessor.Select(feedback => feedback.QuestionOptionId == questionOption.Id)
                .Count();
        }
    }
}
